package com.diandian.backend.dingding.exchange.controller;

import com.aliyun.dingtalkhrm_1_0.models.QueryPositionsResponse;
import com.diandian.backend.dingding.exchange.service.DingdingTokenService;
import com.diandian.dingding.boot.starter.service.DingdingApplicationIntelligentHrPositionManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/intelligence/hr/position/manage")
public class DingdingIntelligenceHrPositionManageController {

    @Autowired
    private DingdingApplicationIntelligentHrPositionManageService intelligentHrPositionManageService;

    @Autowired
    private DingdingTokenService dingdingTokenService;

    /**
     * 获取企业职位列表
     * @return
     */
    @GetMapping("/getRoleGroupList")
    public QueryPositionsResponse getRoleGroupList(@RequestHeader(value = "appKey") String appKey,
                                                   @RequestHeader(value = "appSecret") String appSecret,
                                                   @RequestParam(value = "nextToken") Integer nextToken,
                                                   @RequestParam(value = "maxResults") Integer maxResults,
                                                   @RequestParam(value = "positionName", required = false) String positionName,
                                                   @RequestParam(value = "inCategoryIds", required = false) List<String> inCategoryIds,
                                                   @RequestParam(value = "inPositionIds", required = false) List<String> inPositionIds,
                                                   @RequestParam(value = "deptId", required = false) Long deptId) throws Exception {
        String token = dingdingTokenService.getToken(appKey, appSecret);
        return intelligentHrPositionManageService.queryPositions(token, nextToken, maxResults, positionName,  inCategoryIds, inPositionIds, deptId);
    }
}
